﻿using ProxyKit;

namespace WebAPI.Configure
{
    public class ProxyHandler : IProxyHandler
    {
        private IConfiguration _upstreamHostLookup;

        public ProxyHandler(IConfiguration upstreamHostLookup)
        {
            _upstreamHostLookup = upstreamHostLookup;
        }

        public Task<HttpResponseMessage> HandleProxyRequest(HttpContext context)
        {

            var host = context.Request.Host;
            //var upstreamHost = _upstreamHostLookup.Find(context);
            //return context
            //    .ForwardTo(upstreamHost)
            //    .AddXForwardedHeaders()
            //    .Send();
            //context.Request.Host = new HostString("localhost");

            if (context.Request.Path.Value.StartsWith("/v1/file/filePre"))
            {
                return context.ForwardTo(new UpstreamHost("http://11.11.142.130:8037")).AddXForwardedHeaders().Send();
            }

            return Task.FromResult<HttpResponseMessage>(null);
        }
    }
}
